<template>
	<view class="container">

		<view class="form">
			<view class="form-item">
				<text class="label">家长码：</text>
				<input class="input" type="text" v-model="parentCode" placeholder="请输入家长码" />
			</view>
			<view class="button-wrapper">
				<button class="button" @click="onParentCode">绑定</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		babyRelationAdd
	} from '@/api/api.js'
	export default {
		data() {
			return {
				parentCode: '',
			}
		},
		methods: {
			onParentCode() {
				babyRelationAdd(this.parentCode).then(res => {
					console.log(res.data)
					if (res.data.code != 0) {
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					} else {
						uni.showToast({
							icon: "none",
							title: "新增成功"
						})
						uni.reLaunch({
							url: '/pages/index/index'
						});

					}
				})
			}
		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100vh;
		background-color: #f5f5f5;
	}

	.logo {
		width: 120px;
		height: 120px;
		margin-bottom: 20px;
	}

	.form {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 80%;
		background-color: #fff;
		border-radius: 10px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
		padding: 20px;
	}

	.form-item {
		display: flex;
		align-items: center;
		margin-bottom: 20px;
	}

	.label {
		width: 80px;
		font-size: 16px;
		color: #333;
	}

	.input {
		flex: 1;
		font-size: 16px;
		padding: 10px;
		border: 1px solid #ccc;
		border-radius: 5px;
	}

	.button-wrapper {
		display: flex;
		justify-content: center;
	}

	.button {
		font-size: 16px;
		color: #fff;
		background-color: #007aff;
		border-radius: 5px;
		padding: 10px 20px;
		border: none;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
		transition: all 0.3s ease;
	}

	.button:hover {
		transform: translateY(-2px);
		box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
	}
</style>